A wide variety of mediums carry data between computing devices. For example, a computer can communicate with other network devices through wire, optic, or wireless mediums. These mediums carry signals representing the 1-s and 0-s used in digital systems. For example, a particular voltage in a copper wire may identify a “1” while another voltage identifies a “0”.
Unfortunately, communication errors sometime occur, for example, due to noise or other problems. To reduce the potential impact of communication errors, many network devices communicate using logical groupings of bits known as frames. Typically, in addition to a payload of data, a frame often includes data that enables a receiver to detect and, potentially, correct transmission errors. The frame may also include other information such as the description of the payload (e.g., Internet Protocol packets).
Many protocols reserve special sequences of bits, known as flags, to encode information. For example, some protocols define flags that identify the start and end of a frame. For instance, a protocol known as High-Level Data Link Control (HDLC) reserves the bit sequence “01111110” (six “1”-s sandwiched by “0”-s) to identify the start and end of a frame. Thus, an HDLC frame is structured as:                [01111110]—frame data—[01111110].An HDLC receiver can, therefore, identify the start and end of a frame by detecting the sequence of bits reserved for the start and end flags. Potentially, however, some sequence of bits within the frame may coincidentally happen to be the same as a sequence of bits in a flag. To prevent misinterpretation of frame data as a flag, HDLC uses a technique known as bit-stuffing. To perform bit stuffing in HDLC, a sender inserts a “0” whenever five consecutive “1”-s are encountered. For example, frame data of        “ . . . 0011111101 . . . ”would be transmitted as        “ . . . 00111110101 . . . ”where the underlined “0” represents a stuffed bit. To recover the intended frame contents, a receiver strips a “0” following five consecutive “1”-s. Framing protocols also define other flags such as an abort flag (e.g., seven or more consecutive “1”-s) that indicates aborted transmission of a frame.        